//
//  ViewController.m
//  UIProgressViewDemo1
//
//  Created by 李煜 on 2024/3/8.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic,strong) UIView *blueView;
@property (nonatomic,strong) UIProgressView *pView;
@property (nonatomic,strong) NSTimer *timer;
@property (nonatomic,assign) NSUInteger num;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *b = [[UIView alloc]initWithFrame:CGRectMake(0, 200, 10, 10)];
    [self.view addSubview:b];
    b.backgroundColor = [UIColor blueColor];
    self.blueView = b;
    NSLog(@"---blueView%@",NSStringFromCGRect(self.blueView.frame));

    UIProgressView *p = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 100, 300, 10)];
    [self.view addSubview:p];
    self.pView = p;
    p.trackTintColor = [UIColor grayColor];
    p.progressTintColor = [UIColor redColor];

    __weak typeof(self) weakSelf =self;
    NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        weakSelf.num += 20.0;
        CGFloat progress = weakSelf.num/100.0;
        weakSelf.pView.progress = progress;

        if (floor(progress) == 1) {
            [weakSelf.timer invalidate];
        }
    }];
    self.timer = t;
}
-(void)dealloc {
    self.timer = nil;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (self.blueView.subviews.count > 0) {
        [self.blueView.subviews.firstObject removeFromSuperview];
    }
///#XcodeTranslater:
///  1. v. 使改观，使变形，使转化；变换（电流）的电压；（数）变换（数学实体）
/// 2. n. （数，语言学）变换式，转换句；（数，语言学）转换规则
/// 美式发音: trænsˈfɔːrm  英式发音:trænsˈfɔːm
    //UIProgressView高只能通过transform设置宽高
    self.pView.transform = CGAffineTransformMakeScale(2, 8.f);
    NSLog(@"---pView%@",NSStringFromCGRect(self.pView.frame));

    self.blueView.transform = CGAffineTransformMakeScale(10, 10);
    NSLog(@"---blueView%@",NSStringFromCGRect(self.blueView.frame));
//self.blueView.transform3D
//    self.blueView.layer.transform
    UIView *bsubView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 5)];
    [_blueView addSubview:bsubView];
    bsubView.backgroundColor = [UIColor orangeColor];
}
@end
